<template>

    <div>
        <el-form :model="model" :rules="rules" ref="ruleForm" label-width="100px" class="demo-ruleForm">

            <el-form-item label="器具编号" prop="DeviceCode">
                <el-input v-model="model.DeviceCode"></el-input>
            </el-form-item>

            <el-form-item label="器具名称" prop="DeviceName">
                <el-input v-model="model.DeviceName"></el-input>
            </el-form-item>

            <el-form-item label="数据协议" prop="Agreement">
                <el-select v-model="model.Agreement" placeholder="请选择数据协议">
                    <el-option label="TCP/IP" value="TCP/IP"></el-option>
                    <el-option label="HTTP" value="HTTP"></el-option>
                    <el-option label="MOTT" value="MOTT"></el-option>
                    <el-option label="Modbus" value="Modbus"></el-option>
                    <el-option label="蓝牙" value="蓝牙"></el-option>
                    <el-option label="其他" value="其他"></el-option>
                    <el-option label="无" value="无"></el-option>
                </el-select>
            </el-form-item>

            <el-form-item class="page-box-footer">
                <el-button type="primary" @click="submitForm">{{ isUpdate?'立即保存':'立即创建' }}</el-button>
                <el-button @click="resetForm">重置</el-button>
            </el-form-item>


        </el-form>

    </div>

</template>

<script>
export default {
    props:{
        model: {
            required: true,
            type: Object
        },
        isUpdate: {
            required: true,
            type: Boolean
        }
    },
    data(){
        return {
            UnitMeasureList:[],
            rules: {
                DeviceCode: { required: true, message: '请输入器具编号', trigger: 'blur' },
                DeviceName: { required: true, message: '请输器具名称', trigger: 'blur' },
                Agreement: { required: true, message: '请选择数据协议', trigger: 'blur' },
            }
        }
    },
    created(){
        this.GetQcProjectDeviceAll();
    },
    methods:{
        submitForm(){
            this.$refs['ruleForm'].validate((valid)=>{
                if(valid){
                    if(this.isUpdate){
                        this.put();
                    }
                    else{
                        this.add();
                    }
                } else{
                    this.showNotify('请输入必填项');
                    return false;
                }
            });
        },
        resetForm() {
        this.$refs['ruleForm'].resetFields();
    },
    
    //新增
    add(){
        this.$http.postForm('/api/QcProjectDevice',{model:this.model},{loading:this.$loading()})
        .then(res=>{
            this.$emit('callback');
        })
    },

    //修改
    put(){
        this.$http.putForm('/api/QcProjectDevice',{model:this.model},{loading:this.$loading()})
		.then((res)=>{
            this.$emit('callback');
		})
    },
    GetQcProjectDeviceAll(){
        this.$http.get('/api/QcProjectDevice/GetAll')
        .then(res=>{
            this.UnitMeasureList=res.Data ;
        })
    }
    }


}
</script>

<style></style>